import { getEnterPriseListAPI, getIndustryListAPI } from '@/apis';
import type { Enterprise, EnterpriseListParams, IndustryItem } from '@/types/enterprise';
import { onMounted, ref } from 'vue';
export const useEnterPrise = () => {
    const totalNum = ref(0) // 总数
    const list = ref<Enterprise[]>([])
    const queryParams = ref<EnterpriseListParams>({
        name: '',
        page: 1,
        pageSize: 10
    }) //   请求参数

    onMounted(() => {
        getEnterPriseList()
    })
    const getEnterPriseList = async () => {
        const { total, rows } = await getEnterPriseListAPI(queryParams.value)
        list.value = rows // 列表
        totalNum.value = total // 总数
    }

    const changePage = (newPage: number) => {
        queryParams.value.page = newPage // 赋值新页码
        getEnterPriseList() // 重新加载
    }
    return { list, totalNum, changePage, queryParams }
}

// 导出一个获取行业列表hook
export const useIndustry = () => {
    const IndustryList = ref<IndustryItem[]>([])
    onMounted(() => {
        getIndustryList()
    })
    const getIndustryList = async () => {
        IndustryList.value = await getIndustryListAPI()
    }

    return { IndustryList }
}